<?php

namespace app\api\model;

use app\api\service\Api;
use think\Db;
use think\Request;

class MenuModel extends Api
{
    protected static $instance;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
    }

    public static function getInstance()
    {
        if (is_null(self::$instance))
        {
            self::$instance = new static();
        }
        return self::$instance;
    }

    /**
     * 添加菜单
     */
    public function add($data)
    {
        Db::name('auth_rule')->insert($data);
        return Db::name('auth_rule')->getLastInsID();
    }

    /**
     * 编辑菜单
     */
    public function edit($where, $data)
    {
        return Db::name('auth_rule')->where($where)->update($data);
    }

    /**
     * 查询菜单
     */
    public function select($where, $field = '*')
    {
        return Db::name('auth_rule')->where($where)->order('weigh')->field($field)->select();
    }

    /**
     * 查询指定菜单
     */
    public function find($where)
    {
        $info = Db::name('auth_rule')->where($where)->find();
        return $info;
    }

    /**
     * 获取指定字段
     */
    public function column($where, $value)
    {
        $value = Db::name('auth_rule')->where($where)->column($value);
        return $value;
    }

}